package com.sxkf.template.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;

import static com.sxkf.template.mq.QueueConfig.*;

@Component
public class Producer {

    @Resource
    private RabbitTemplate rabbitTemplate;


    // 延迟发送，延迟delay秒
    public void sendWithDelay(String str, Integer delay) {
        MessageProperties properties = new MessageProperties();
        properties.setDelay(delay*1000);
        Message message = new Message(str.getBytes(), properties);
        rabbitTemplate.send(EX_DELAYED, R_DELAYED, message);
    }

}
